#ifndef __HK32E23x_HAL_TTY_H__
#define __HK32E23x_HAL_TTY_H__

#include <stdint.h>

#define TTY_BAUDRATE			        115200U

#define TTY_TXBUFFER_SIZE				32
#define TTY_RXBUFFER_SIZE				16

#define TTY_HALF_RX_BUFFER_SIZE	        8

#define TTY_TXFIFO_SIZE                 64
#define TTY_RXFIFO_SIZE                 64

#define TTY_UART_IO_RCU         RCC_AHBPeriph_GPIOA
#define TTY_UART_IO_BASE        GPIOA

#define TTY_UART_TX_PIN         GPIO_Pin_9
#define TTY_UART_RX_PIN         GPIO_Pin_10

#define TTY_RX_PIN_SOURCE       GPIO_PinSource10
#define TTY_TX_PIN_SOURCE       GPIO_PinSource9

#define TTY_UART_RCU            RCC_APB2Periph_UART1
#define TTY_UART_CORE           UART1
#define TTY_UART_IRQ			UART1_IRQn

#define DMA_UART_REMAP			0

#if DMA_UART_REMAP
	#define TTY_DMA_TX_CHANNEL      DMA_Channel4
	#define TTY_DMA_RX_CHANNEL      DMA_Channel5
#else
	#define TTY_DMA_TX_CHANNEL      DMA_Channel2
	#define TTY_DMA_RX_CHANNEL      DMA_Channel3
#endif

typedef struct {
    void (*init)(void);                             //初始化
    uint16_t (*write)(void *buf, uint16_t len);     //数据写
    uint16_t (*read) (void *buf, uint16_t len);     //数据读
    void (*puts)(const char *str);                  //输入一个字符串
    void (*clr)(void);                              //清除接收缓冲区
    uint16_t (*buflen)(void);                       //接收缓冲区的长度
    void (*printf)(const char *format, ...);        //格式化打印
}tty_t;

extern const tty_t g_tty_;

extern void UART1_IRQHandler(void);
#endif //__HK32E23x_HAL_TTY_H__
